﻿@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>学生用户管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 3)
    <div class="container mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="@Url.Action("StudentList", "UserInfo")?@para"><span class="glyphicon glyphicon-list"></span> 学生用户列表</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="@Url.Action("AddStudent", "UserInfo")?@para"><span class="glyphicon glyphicon-user"></span> 新增学生用户</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="javascript:void(0)"><span class="glyphicon glyphicon-list"></span> 学生用户组列表</a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="@Url.Action("AddStudentGrp", "UserInfo")?@para"><span class="glyphicon glyphicon-plus"></span> 新增学生用户组</a>
                        </li>
                    </ul>
                </div>
            </div> 
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <ol class="breadcrumb">
                            <li>学生用户管理</li>
                            <li>学生用户组列表</li>
                            <li class="active">成员管理</li>
                        </ol>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <ul id="myTab" class="nav nav-tabs">
                                <li class="active"><a href="#home" data-toggle="tab">单个新增</a></li>
                                <li><a href="#ios" data-toggle="tab">批量导入</a></li>
                            </ul>
                            <div id="myTabContent" class="tab-content pt15 mb15 b3">
                                <div class="tab-pane fade in active" id="home">
                                    <div class="form-group clearfix">
                                        <div class="col-xs-6">
                                            <input type="text" class="form-control" id="JaddAccount" placeholder="请输入学号">
                                        </div>
                                        <div class="col-xs-6">
                                            <button type="button" id="JaddStd" class="btn btn-success">新增</button>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="ios">
                                    <div class="form-group clearfix">
                                        <div class="col-xs-6">
                                            
                                            <input name="fileName" id="JfileName" class="form-control mb10" readonly="readonly" />                                            
                                                <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">
                                            <br/>
                                            <button type="button" id="JaddStdGrp" class="btn btn-success">导入</button>
                                        </div>
                                        <div class="col-xs-6">
                                            <a class="red" href="../../res/template/批量导入学生信息模板.xlt" >Excel模版下载</a><br />
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <div class="col-xs-4">
                                        <input type="text" class="form-control" id="Jaccount" placeholder="请输入学号">
                                    </div>
                                    <div class="col-xs-2">
                                        <button type="button" id="Jsearch" class="btn btn-success">搜索</button>
                                    </div>
                                    <div class="cols-sm-6"></div>
                                </div>
                            </form>
                        </div>
                        <div class="row">
                            <table class="table table-bordered tb1">
                                <thead>
                                    <tr>
                                        <th width="30%">学号</th>
                                        <th width="20%">姓名</th>
                                        <th width="20%">创建时间</th>
                                        <th width="30%">操作</th>
                                    </tr>
                                </thead>
                                <tbody id="JgrpTbody">
                                </tbody>
                            </table>
                        </div>
                        <div class="row clearfix well">
                            <div id="PagInfo" class="pull-left sum"></div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script type="text/javascript" src="../Js/uploadToggle.js"></script>
    <script type="text/javascript">
        //上传文件
        var _attachmentUrl = null;

        $(function () {
            uploadToggle('/Base/UpLoad', {  'fileType': 'OtherFile' }, function (file, data) {
                var json = $.parseJSON(data);
                if (json.result) {
                    _attachmentUrl = json.message; //文件保存的地址
                    $("#JfileName").val(file.name);
                    $("#JfileName").attr("data-fileUrl", _attachmentUrl);
                }
                else {
                    showTips.open(json.message);
                }
            });


            // $("#file_upload").uploadify({
            //     'queueSizeLimit': 1,
            //     //fileType代表文件类型的值可能有:   Image 、 OtherFile 、 Temp
            //     'formData': { 'fileType': 'OtherFile' },
            //     'buttonText': '请选择上传文件',
            //     'swf': '../Content/uploadify/uploadify.swf',
            //     'uploader': '/Base/UpLoad',
            //     'onUploadSuccess': function (file, data, response) {
            //         var json = $.parseJSON(data);
            //         if (json.result) {
            //             _attachmentUrl = json.message; //文件保存的地址
            //             $("#JfileName").val(file.name);
            //             $("#JfileName").attr("data-fileUrl", _attachmentUrl);
            //         }
            //         else {
            //             showTips.open(json.message);
            //         }
            //     }
            // });
        });


    </script>
    <script>
        var _page = 1,
            _grpId = $.getUrlParam("GrpId") ? $.getUrlParam("GrpId") : "",
            grpTbody = $("#JgrpTbody"),
            _account = "";

        function getList(pageNo, grpid) {
            _page = pageNo;
            _grpId = grpid;
            $.easyPost("@Url.Action("GetUserInfoByGrp", "UserInfo")", {
                "PageNO": pageNo,
                "PageSize": 10,
                "GrpId": grpid
            }, function (data) {
                if (!data.result) {
                    showTips.open(data.message);
                    return;
                }
                if (data.rows.length > 0) {
                    var _row = data.rows,
                        _rowL = _row.length,
                        _html = '';
                    var options = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: pageNo,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getList(page, grpid);
                        }
                    }
                    initialPaginator(options, "PageTool", "PagInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var _grpInfo = _row[i];
                        var time = new Date();
                        if (_grpInfo.CreateTime) {
                            var _date = _grpInfo.CreateTime.toString().replace(/\//g, "");
                            time = eval('new ' + _date);
                        }                       
                        _html += '<tr data-grpid=\"' + _grpInfo.Id.trim() + '\">' +
                                     '<td class=\"account\">' + _grpInfo.Account + '</td>' +
                                     '<td class=\"realName\">' + _grpInfo.RealName + '</td>' +
                                     '<td>' + time.format('yyyy-MM-dd') + '</td>' + 
                                     '<td>' +
                                         '<a class=\"operate aDelete\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-trash\"><\/span> 删除<\/a>' +                                         
                                     '</td>' +
                                 '</tr>'
                    }
                    grpTbody.html(_html)
                } else {
                    var _html = '<tr><td colspan="4" align="center">暂无内容</td></tr>'
                    grpTbody.html(_html)
                }
            }, "json");
        }
        getList(_page, _grpId);
        function getStd(_page, account) {
            _account = account;
            $.easyPost("@Url.Action("GetUserInfoListByGrpId", "UserInfo")", {
                "PageNO": _page,
                "PageSize": 10,
                "GrpId": _grpId,
                "Account": account
            }, function (data) {
                if (!data.result) {
                    showTips.open(data.message);
                    return;
                }
                if (data.rows.length > 0) {
                    var _row = data.rows,
                        _rowL = _row.length,
                        _html = '';
                    var options = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: _page,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getStd(page, _account);
                        }
                    }
                    initialPaginator(options, "PageTool", "PagInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var _grpInfo = _row[i];
                        var time = new Date();
                        if (_grpInfo.Entity.CreateTime) {
                            var _date = _grpInfo.Entity.CreateTime.toString().replace(/\//g, "");
                            time = eval('new ' + _date);
                        }
                        _html += '<tr data-grpid=\"' + _grpInfo.Entity.Id.trim() + '\">' +
                                     '<td class=\"account\">' + _grpInfo.Entity.Account + '</td>' +
                                     '<td class=\"realName\">' + _grpInfo.Entity.RealName + '</td>' +
                                     '<td>' + time.format('yyyy-MM-dd') + '</td>' +
                                     '<td>' +
                                         '<a class=\"operate aDelete\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-trash\"><\/span> 删除<\/a>' +
                                     '</td>' +
                                 '</tr>'
                    }
                    grpTbody.html(_html)
                } else {
                    var _html = '<tr><td colspan="4" align="center">暂无内容</td></tr>'
                    grpTbody.html(_html)
                }
            })
        }
        $("#Jsearch").bind("click", function () {
            var _act = $("#Jaccount").val();
            getStd(1, _act);
        })
        var JaddAccount = $("#JaddAccount");
        $("#JaddStd").bind("click", function () {
            var _addAccount = JaddAccount.val();
            $.easyPost("@Url.Action("AddStudentToGrp", "GrpManage")", {
                "GrpId": _grpId,
                "Account": _addAccount
            }, function (data) {
                if (!data.result) {
                    showTips.open(data.message);
                    return;
                } else {
                    showTips.open("新增成功！")
                    getList(_page, _grpId);
                }
            })
        })
        $("#JaddStdGrp").bind("click", function () {
            var Jfile = $("#JfileName").attr("data-fileUrl");
            $.easyPost("@Url.Action("AddStudentsToGrp", "GrpManage")", {
                "GrpId": _grpId,
                "FilePath": Jfile                
            }, function (data) {
                if (data.result) {
                    showTips.open("添加成功！");
                    getList(_page, _grpId);
                    return;
                } else {
                    showTips.open(data.message);
                    return;
                }
            }, "json")
        })
        grpTbody.bind("click", function (e) {
            var _self = $(e.target);
            if (_self.hasClass("aDelete") || _self.parent().hasClass("aDelete")) {
                var _edit = _self.hasClass("aDelete") ? _self : _self.parent(),
                    _tr = _edit.parent().parent(),
                    _id = _tr.attr("data-grpid");
                $.easyPost("@Url.Action("RemoveStudentFromGrp", "GrpManage")", {
                    "GroupId": $.getUrlParam("GrpId"),
                    "UserId": _id
                }, function (data) {
                    if (data.result) {
                        showTips.open("删除成功！");
                        getList(_page, _grpId);
                        return;
                    } else {
                        showTips.open(data.message);
                        return;
                    }
                }, "json")
            }
        })
    </script>
</body>
</html>